﻿using dotnet.config;
using Microsoft.EntityFrameworkCore;

namespace dotnet.Extensions
{
    public static class ServiceCollectionExtensions
    {
        public static void AddCustomerCors(this IServiceCollection services)
        {
            services.AddCors(option =>
            {
                option.AddPolicy("AllowAll", builder =>
                {
                    builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyMethod();
                });
            });
        }

        public static void AddDbContext(this IServiceCollection services, string connectionString)
        {
            services.AddDbContext<MyDbContext>(options => options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)));
        }
    }
}
